package com.yuexun.dhdoctor.module.Contract.presenter.impl;


import com.yuexun.dhdoctor.module.Contract.bean.DeleteGroupBean;
import com.yuexun.dhdoctor.module.Contract.model.IManageGroupModel;
import com.yuexun.dhdoctor.module.Contract.presenter.IManageGroupPresenter;
import com.yuexun.dhdoctor.module.Contract.ui.view.IManageGroupView;

import org.kymjs.kjframe.ui.ViewInject;

import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by work-jx on 2016/7/26.
 */
public class ManageGroupPresenter implements IManageGroupPresenter {
    private IManageGroupView view;
    private IManageGroupModel model;

    //记录Log
//    private final Logger log = ProUtil.getLogger(LoginPresneter.class);

    public ManageGroupPresenter(IManageGroupModel model, IManageGroupView view) {
        this.model = model;
        this.view = view;
    }

    @Override
    public void deleteGroup(Map<String, String> praise) {
        model.deleteGroup(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<DeleteGroupBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("删除群组失败");
                    }

                    @Override
                    public void onNext(DeleteGroupBean deleteGroupBean) {
                        view.deleteGroup(deleteGroupBean);
                    }
                });
    }

    @Override
    public void updateGroup(Map<String, String> praise) {
        model.updateGroup(praise)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<DeleteGroupBean>() {

                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        ViewInject.toast("更新群组失败");
                    }

                    @Override
                    public void onNext(DeleteGroupBean deleteGroupBean) {
                        view.updateGroup(deleteGroupBean);
                    }
                });
    }

}
